package com.hotdog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hotdog.pojo.IndexInfo;
import com.hotdog.pojo.TbWatchLogs;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (TbWatchLogs)表数据库访问层
 *
 * @author makejava
 * @since 2021-09-11 14:30:48
 */
public interface TbWatchLogsMapper extends BaseMapper<TbWatchLogs> {
    /**
     * 查询一共有多少播放记录
     * @param username
     * @return
     */
    @Select("SELECT COUNT(1) from tb_watch_logs logs RIGHT JOIN viewaddr vi ON `logs`.watch_addr=vi.viewaddr\n" +
            "WHERE `logs`.username=#{username} AND `logs`.watch_total=vi.title")
   int getUserName(String username);

    /**
     * 根据用户名查询播放历史最终查询出播放的主页的视频信息
     * @param username 用户名
     * @param start 查新开始的地方
     * @param size 查询的条数
     * @return
     */
    @Select("SELECT DISTINCT vi.id,vi.auto,vi.title,vi.uploaddata,vi.viewaddr,vi.url\n" +
            " from tb_watch_logs logs RIGHT JOIN viewaddr vi ON `logs`.watch_addr=vi.viewaddr\n" +
            "WHERE `logs`.username=#{username} AND `logs`.watch_total=vi.title LIMIT #{start},#{size}")
    List<IndexInfo> getinfo(@Param("username")String username,@Param("start") Integer start, @Param("size") Integer size);
}

